package springBootweb.com.dome.lession1.service;

import java.io.IOException;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import springBootweb.com.dome.lession1.domain.WeatherAPI;

@Service
public class WeatherService {

	public JSONObject getWeatherAPI() {
		JSONObject jsonObject = null;
		OkHttpClient client = new OkHttpClient();
		Request request = new Request.Builder().url("https://www.sojson.com/open/api/weather/json.shtml?city=深圳")
				.build();
		try {
			Response response = client.newCall(request).execute();
			// WeatherAPI weatherAPI = new WeatherAPI();
			jsonObject = JSONObject.parseObject(response.body().string());
			// Object object = jsonObject.get("date");
			// System.out.println(response.body().string());
			// System.out.println(object);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jsonObject;
	}
	// Welcome welcome = JSON.parseObject(json, Welcome.class);

	public static void main(String[] args) {
		OkHttpClient client = new OkHttpClient();
		Request request = new Request.Builder().url("https://www.sojson.com/open/api/weather/json.shtml?city=深圳")
				.build();

		try {
			Response response = client.newCall(request).execute();
			WeatherAPI weatherAPI = new WeatherAPI();
			JSONObject jsonObject = JSONObject.parseObject(response.body().string());
			// Object object = jsonObject.get("date");
			// System.out.println(response.body().string());
			// System.out.println(object);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
